//
//  MoreSettingsViewController.m
//  NiuBanJin
//
//  Created by Billy on 15/10/10.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "MoreSettingsViewController.h"
#import "SafeCentreViewController.h"
#import "HelpCentreViewController.h"
#import "WebViewController.h"
#import "SuggestUsViewController.h"
#import "InviteFirendsViewController.h"
#import "ContactUsViewController.h"
#import "RetrievingPWDViewController.h"

@interface MoreSettingsViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong) NSArray *array_moreArr1;
@property (nonatomic , strong) NSArray *array_imageArr1;
@property (nonatomic , strong) NSArray *array_moreArr2;
@property (nonatomic , strong) NSArray *array_imageArr2;
@property (nonatomic , strong) NSArray *array_moreArr3;
@property (nonatomic , strong) NSArray *array_imageArr3;
@property (nonatomic , strong) NSString *activity;
@end

@implementation MoreSettingsViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self loadTableView];
}
-(void)getDataFormNet {
    NSDictionary *dic_info = @{@"userId" : GETCURRENTUSERINOBYPRAMETERES(user_userId) , @"token" : GETCURRENTUSERINOBYPRAMETERES(user_userToken)};
    [[NETWorkingUtil sharedNETWorking] zzjrMore_moreInfoByParmeteres:dic_info  transferResultUsingBlock:^(id parsedData, NSError *error) {
        if (!error) {  //没有网络错误
            
            // 开始解析数据
            NSDictionary *dic = parsedData;
            
            if([dic[@"status"] intValue] == 0) {
                
                NSDictionary *dic_result = dic[@"result"];
                self.activity = dic_result[@"activeCenter"];
                
                } else {// 不是网络出错, 其它错误
                
                [UsefulUtil showAlertView:dic[@"msg"]];
                
            }
        }else {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            [UsefulUtil showAlertView:@"遇到网络问题,请稍后重试!"];
            
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"更多";

    self.navigationItem.leftBarButtonItem = nil;
    
    [self getDataFormNet];
}
-(void)loadTableView {
    
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        [tableView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
    
    UIView *view_footView = [[UIView alloc]initWithFrame:CGRectZero];
    [tableView setTableFooterView:view_footView];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    NSString *str_activity = @"";
    if ([str_activity isEqualToString: @""]) {
        
        self.array_moreArr1 = @[@"安全保障" , @"帮助中心" ];
        self.array_imageArr1 = @[@"more-aqzx.png" , @"more-bzzx.png"];
    }else {
        self.array_moreArr1 = @[@"安全中心" , @"帮助中心" , str_activity];
        self.array_imageArr1 = @[@"more-aqzx.png" , @"more-bzzx.png", @"activity.png"];
    }
    
    self.array_moreArr2 = @[ @"牛钱包介绍" , @"关于我们"  , @"意见反馈" ];
    self.array_imageArr2 = @[@"more-nqbjs.png" , @"more-gywm.png" ,  @"more-yjfk.png"];
    self.array_moreArr3 = @[@"邀请好友" ];
    self.array_imageArr3 = @[@"more-yqhy.png" ];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    CGFloat height = 0.0 ;
    if (section == 0) {
       height = 30;
    }
    if (section == 1) {
        height = 30;
        
    }
    if (section == 2) {
        height = 30;
    }
    return height;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSInteger  number = 0;
    if (section == 0) {
        number = self.array_moreArr1.count;
        
    }
    if (section == 1) {
        number = self.array_moreArr2.count;
        
    }
    if (section == 2) {
        number = self.array_moreArr3.count;
    }
    return number;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    static NSString *cellID = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (nil == cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
        
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15.0];
    cell.textLabel.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (indexPath.section == 0) {
        
        cell.textLabel.text = [self.array_moreArr1 objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[self.array_imageArr1  objectAtIndex:indexPath.row]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
}
    if (indexPath.section == 1) {
        cell.textLabel.text = [self.array_moreArr2 objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[self.array_imageArr2 objectAtIndex:indexPath.row]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    if (indexPath.section == 2) {
        cell.textLabel.text = [self.array_moreArr3 objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[self.array_imageArr3 objectAtIndex:indexPath.row]];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        WebViewController *webVC = [[WebViewController alloc]init];
        webVC.index = 7;
        webVC.hidesBottomBarWhenPushed  = YES;
        [self.navigationController pushViewController:webVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        HelpCentreViewController *helpVC = [[HelpCentreViewController alloc]init];
        [helpVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:helpVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 0 && indexPath.row == 2) {
        WebViewController *webVC  = [[WebViewController alloc]init];
       webVC.index = 8;
        [webVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:webVC animated:YES];

    }else {
        
    }
    if (indexPath.section == 1 && (indexPath.row == 0 || indexPath.row == 1) ) {
        WebViewController *webVC = [[WebViewController alloc]init];
        webVC.index = indexPath.row + 4;
        [webVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:webVC animated:YES];
    }else {
        
    }
    if (indexPath.section == 1 && indexPath.row == 2) {
        ContactUsViewController *contactVC = [[ContactUsViewController alloc]init];
        [self.navigationController pushViewController:contactVC animated:YES];
        
    }else {
        
    }
    if (indexPath.section == 1 && indexPath.row == 3) {
        SuggestUsViewController *suggestVC = [[SuggestUsViewController alloc]init];
        [suggestVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:suggestVC animated:YES];

    }else {
        
    }
    if (indexPath.section == 2 && indexPath.row == 0 ) {
        InviteFirendsViewController *InviteVC = [[InviteFirendsViewController alloc]init];
        [InviteVC setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:InviteVC animated:YES];
        
    }else {
        
    }
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
